﻿package com.best.oasis.settlement.biz.facade.system
{
	import com.best.oasis.flexbase.util.BeanUtils;
	import com.best.oasis.flexbase.util.tree.TreeNode;
	import com.best.oasis.settlement.biz.facade.base.OldBaseFacade;
	import com.best.oasis.settlement.biz.facade.base.SuperResponder;
	import com.best.oasis.settlement.common.error.ErrorCode;
	import com.best.oasis.settlement.common.model.ModelLocator;
	import com.best.oasis.settlement.common.vo.system.MenuItemVO;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	/**
	 * 系统菜单操作类
	 * @author bl00064
	 * 
	 */	
	public class MenuItemFacade extends OldBaseFacade
	{

		
		/**
		 * 获取用户的菜单树
		 * @param groupId
		 * @param callback
		 * 
		 */
		public function getMenuItemTree(callback:Function):void{
			
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var result:TreeNode = TreeNode(event.result);
					if(callback != null){
						callback(result);
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取当前用户菜单失败！" + event.fault.faultString);
				});
			delegate.getMenuItemTree().addResponder(responder);
			
		}
		
		public function getList(list:ArrayCollection,callback:Function=null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var menuItem:MenuItemVO = new MenuItemVO();
					var result:ArrayCollection = ArrayCollection(event.result);
					BeanUtils.copyProperties(list, result);
					if(callback != null){
						callback(result);
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("获取菜单列表失败！" + event.fault.faultString);
				});
			//var delegate:MenuItemDelegate = new MenuItemDelegate(responder);
			delegate.getList().addResponder(responder);
		}
		
		public function saveOnEdit(list:ArrayCollection,callback:Function=null):void{
			var responder:SuperResponder = new SuperResponder(
				function(event:ResultEvent):void{
					var tResult:ArrayCollection = ArrayCollection(event.result);
					if(tResult!= null && tResult.length >0){
						Alert.show("保存成功！");
					}
					if(callback != null){
						callback();
					}
				}, 
				function(event:FaultEvent):void{
					trace(event.fault);
					Alert.show("保存失败！" + event.fault.faultString);
				});
			//var delegate:MenuItemDelegate = new MenuItemDelegate(responder);
			delegate.saveOnEdit(list).addResponder(responder);
		}
	}
}